home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / ASTWaveGetter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  4.8 KB  |  154 lines  |  [TEXT/KAHL]

  1. /* ASTWaveGetter.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "ASTWaveGetter.h"
  31. #include "Memory.h"
  32. #include "TrashTracker.h"
  33.  
  34.  
  35. struct ASTWaveGetterRec
  36.     {
  37.         char*                        TheString;
  38.         WaveGetterOp        TheOperation;
  39.     };
  40.  
  41.  
  42. /* create a new AST wave getter form */
  43. ASTWaveGetterRec*        NewWaveGetter(char* SampleName, WaveGetterOp TheOperation,
  44.                                             struct TrashTrackRec* TrashTracker, long LineNumber)
  45.     {
  46.         ASTWaveGetterRec*    WaveGetter;
  47.  
  48.         CheckPtrExistence(SampleName);
  49.         CheckPtrExistence(TrashTracker);
  50.  
  51.         WaveGetter = (ASTWaveGetterRec*)AllocTrackedBlock(sizeof(ASTWaveGetterRec),
  52.             TrashTracker);
  53.         if (WaveGetter == NIL)
  54.             {
  55.                 return NIL;
  56.             }
  57.  
  58.         WaveGetter->TheString = SampleName;
  59.         WaveGetter->TheOperation = TheOperation;
  60.  
  61.         return WaveGetter;
  62.     }
  63.  
  64.  
  65. /* type check the wave getter node.  this returns eCompileNoError if */
  66. /* everything is ok, and the appropriate type in *ResultingDataType. */
  67. CompileErrors                TypeCheckWaveGetter(DataTypes* ResultingDataType,
  68.                                             ASTWaveGetterRec* WaveGetter, long* ErrorLineNumber,
  69.                                             struct TrashTrackRec* TrashTracker)
  70.     {
  71.         CheckPtrExistence(WaveGetter);
  72.         CheckPtrExistence(TrashTracker);
  73.  
  74.         switch (WaveGetter->TheOperation)
  75.             {
  76.                 default:
  77.                     EXECUTE(PRERR(ForceAbort,"TypeCheckWaveGetter:  bad type"));
  78.                     break;
  79.                 case eWaveGetterSampleLeft:
  80.                 case eWaveGetterSampleRight:
  81.                 case eWaveGetterSampleMono:
  82.                 case eWaveGetterWaveArray:
  83.                     *ResultingDataType = eArrayOfFixed;
  84.                     break;
  85.                 case eWaveGetterWaveFrames:
  86.                 case eWaveGetterWaveTables:
  87.                     *ResultingDataType = eInteger;
  88.                     break;
  89.             }
  90.  
  91.         return eCompileNoError;
  92.     }
  93.  
  94.  
  95. /* generate code for a wave getter.  returns True if successful, or False if it fails. */
  96. MyBoolean                        CodeGenWaveGetter(struct PcodeRec* FuncCode,
  97.                                             long* StackDepthParam, ASTWaveGetterRec* WaveGetter)
  98.     {
  99.         CheckPtrExistence(FuncCode);
  100.         CheckPtrExistence(WaveGetter);
  101.  
  102.         switch (WaveGetter->TheOperation)
  103.             {
  104.                 default:
  105.                     EXECUTE(PRERR(ForceAbort,"CodeGenWaveGetter:  bad opcode"));
  106.                     break;
  107.                 case eWaveGetterSampleLeft:
  108.                     if (!AddPcodeInstruction(FuncCode,epGetSampleLeftArray,NIL))
  109.                         {
  110.                             return False;
  111.                         }
  112.                     break;
  113.                 case eWaveGetterSampleRight:
  114.                     if (!AddPcodeInstruction(FuncCode,epGetSampleRightArray,NIL))
  115.                         {
  116.                             return False;
  117.                         }
  118.                     break;
  119.                 case eWaveGetterSampleMono:
  120.                     if (!AddPcodeInstruction(FuncCode,epGetSampleMonoArray,NIL))
  121.                         {
  122.                             return False;
  123.                         }
  124.                     break;
  125.                 case eWaveGetterWaveFrames:
  126.                     if (!AddPcodeInstruction(FuncCode,epGetWaveTableFrames,NIL))
  127.                         {
  128.                             return False;
  129.                         }
  130.                     break;
  131.                 case eWaveGetterWaveTables:
  132.                     if (!AddPcodeInstruction(FuncCode,epGetWaveTableTables,NIL))
  133.                         {
  134.                             return False;
  135.                         }
  136.                     break;
  137.                 case eWaveGetterWaveArray:
  138.                     if (!AddPcodeInstruction(FuncCode,epGetWaveTableArray,NIL))
  139.                         {
  140.                             return False;
  141.                         }
  142.                     break;
  143.             }
  144.         if (!AddPcodeOperandString(FuncCode,WaveGetter->TheString,
  145.             PtrSize(WaveGetter->TheString)))
  146.             {
  147.                 return False;
  148.             }
  149.  
  150.         *StackDepthParam += 1;
  151.  
  152.         return True;
  153.     }
  154.